package 多线程;

/**
 * @Author: 朱胜伟
 * @CreateTime: 2021-02-01 13:36
 * @Description: volatile测试类
 */
public class volatileTest {
    public static void main(String[] args) {
        PrintString ps = new PrintString();
//        ps.pr();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                ps.pr();
//            }
//        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                ps.pr();
            }
        }).start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ps.setCon(false);
    }

    static class PrintString{
        private boolean conti = true;
        public PrintString setCon(boolean bo){
            this.conti = bo;
            return this;
        }
        public void pr(){
            System.out.println("开始。。。。。。。。。。。。");
            while (conti){
//                System.out.println(Thread.currentThread().getName());
//                try {
//                    Thread.sleep(500);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            }
            System.out.println(Thread.currentThread().getName()+"结束");

        }
    }
}
